<?php


/**密码加密函数***/
function crpypassword($str) {
    $key = "afe#fefea";
    return md5(md5(md5($str) . md5($key)));
}

/*产生随机字符串**/
function randStr($len) {
    $len = ($len >= 26) ? 26 : $len;
    $arr = range("a", "z");
    $keys = array_rand($arr, $len);
    $str = "";
    foreach ($keys as $v) {
        $str .= $arr[$v];
    }
    return $str;
}

//把一个字符串指定的位置替换成其他字符
function strReplceOther($str, $s, $e, $flag = "*") {
    $len = mb_strlen($str);
    $new = "";
    for ($i = 0; $i < $len; $i++) {

        if ($i >= $s && $i < $e) {
            $new .= $flag;
        } else {
            $new .= $str[$i];
        }
    }
    return $new;
}

function reN2Br($str) {
    return preg_replace("\s\S", "<br/>", $str);
}

function descId($id) {
    $id = strval($id);
    $result = '';
    $n = strlen($id);
    for ($i = 0; $i < 40; $i++) {
        $ranNum = rand(0, 25);
        //大写字母'A'的ASCII是65,A~Z的ASCII码就是65 + 0~25;然后调用String.fromCharCode()传入ASCII值返回相应的字符并push进数组里
        $result .= chr(65 + $ranNum);
    }

    $f = intval(strlen($result) / $n);
    for ($i = 0; $i < $n; $i++) {
        $pos = intval(lcg_value() * $f) + $f * $i;
        $pos = $pos == 0 ? 1 : $pos;
        $result = substr($result, 0, $pos - 1) . $id[$i] . substr($result, $pos - 1, strlen($result) - 1);
    }
    return $result;

}

function insert_flg($str, $flg, $sn) {
    return substr($str, 0, $sn - 1) . $flg . substr($str, $sn - 1, strlen($str) - 1);
}